package com.itheima_02;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ServerTest {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket =new DatagramSocket(10000);//创建对象
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes,bytes.length);//打包
            socket.receive(packet);//接收
            String s = new String(packet.getData(), 0, packet.getLength());
            System.out.println(packet.getSocketAddress()+" "+new String(packet.getData(), 0, packet.getLength()));
            if (s.equals("886")){
                break;
            }

        }

        socket.close();
    }
}
